import axios from '@ohos/axios'
import categories from '../define/categories'
import configs from '../config/config'
import foods from '../define/foods'
import response from '../define/response'

class FoodModel {
  baseUrl: string = configs.domain + 'api/labaicai/food'

  addFood(enterResult: string, date: string, food: foods, category: categories): Promise<response> {
    console.log("test addFood", `${this.baseUrl}`)
    return new Promise((resolve, reject) => {
      axios.post(this.baseUrl + '/addDiet', {
        food: food,
        category: category,
        enterResult: enterResult,
        date: date
      }).then((rsp) => {
        if (rsp.status === 200) {
          resolve(rsp.data)
        } else {
          console.log("2222", rsp);
          reject("添加食物失败")
        }
      })
        .catch(err => {
          console.log("3333", err);

          reject("添加食物失败")
        })
    })

  }
}

const foodModel = new FoodModel()

export default foodModel as FoodModel